package com.itheima.consumer.mq;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.security.PublicKey;

@Component
public class RepublishMessage {

    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("error.direct");
    }

    @Bean
   public Queue errorQueue(){
        return new Queue("error.queue",true);
    }

    @Bean
    public Binding errorBind(DirectExchange directExchange,Queue errorQueue){
        return BindingBuilder.bind(errorQueue).to(directExchange).with("error");
    }


    @Bean
    public MessageRecoverer republicMessageRecoverer(RabbitTemplate rabbitTemplate){

        return new RepublishMessageRecoverer(rabbitTemplate,"error.direct","error");

    }



}
